class Gun:
    def __init__(self, model):
        self.model = model
        self.bullet_count = 0  # 默认0，无需传

    def add_bullet(self,count):
        print('装弹中')
        self.bullet_count += count

    def shoot(self):
        if self.bullet_count <=0:
            print('没子弹了')
        else:
            print(f'{self.model}开枪{self.bullet_count}')
            self.bullet_count -= 1


class Soldier:
    def __init__(self, name):
        self.name = name
        self.gun = None

    def fire(self):
        if self.gun !=  None:
            print('士兵开火')
            self.gun.shoot()
        else:
            print('士兵没枪')



if __name__ == '__main__':
    # #创建枪对象
    ak47 = Gun('ak47')
    # ak47.add_bullet(50)
    # ak47.shoot()

    xusanduo = Soldier('xusanduo')
    xusanduo.fire()
    xusanduo.gun = ak47
    xusanduo.fire()
    xusanduo.gun.add_bullet(50)
    xusanduo.fire()
